package com.yypx.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.yypx.common.utils.ObjToMapUtil;
import com.yypx.dao.LessonDAO;
import com.yypx.entity.Lesson;
import com.yypx.service.LessonService;

@Component("lessonService")
public class LessonServiceImpl implements LessonService {
	@Autowired
	private LessonDAO lessonDAO;

	@Override
	public void add(Lesson o) {
		lessonDAO.addNew(o);
	}

	@Override
	public void delById(UUID id) {
		lessonDAO.delById(id);
	}

	@Override
	public Lesson findById(UUID id) {
		return lessonDAO.findById(id);
	}

	@Override
	public List<Map<String, Object>> getResultList(List<Lesson> list) {
		if (list == null)
			return null;
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < list.size(); i++) {
			HashMap<String, Object> resultItem = (HashMap<String, Object>) ObjToMapUtil.toHashMap(list.get(i));
			/* 在这个地方可以根据具体的情况对实体的属性的页面返回做处理，比如说1代表可用 ，0代表不可用 */
			handleEntityForPageTemplate(resultItem, list.get(i));
			result.add(resultItem);
		}
		return result;
	}

	@Override
	public Map<String, Object> getResultMap(Lesson o) {
		HashMap<String, Object> resultItem = (HashMap<String, Object>) ObjToMapUtil.toHashMap(o);
		/* 在这个地方可以根据具体的情况对实体的属性的页面返回做处理，比如说1代表可用 ，0代表不可用 */
		handleEntityForPageTemplate(resultItem, o);
		return resultItem;
	}

	@Override
	public void handleEntityForPageTemplate(Map<String, Object> map, Lesson o) {
		// TODO Auto-generated method stub
	}

	@Override
	public List<Lesson> selAll() {
		return lessonDAO.selAll();
	}

	@Override
	public List<Lesson> selAllByCondition(Map map) {
		return lessonDAO.selAllByCondition(map);
	}

	@Override
	public int selCountByCondition(Map map) {
		return lessonDAO.selCountByCondition(map);
	}

	@Override
	public void update(Lesson o) {
		lessonDAO.update(o);
	}
}
